<?php

namespace TuxCocktail\TuxDb\Mysql\Cocktail;

use TuxCocktail\TuxDb\TuxGlassTypeInterface;
use TuxCocktail\TuxDb\Mysql\Cocktail\Model\GlassTypeTable;
use TuxCocktail\TuxDb\Mysql\TuxDbMysqlAbstract;


class TuxDbMysqlGlassType extends TuxDbMysqlAbstract implements TuxGlassTypeInterface {

	
	/**
	 * 
	 * @var GlassTypeTable
	 */
	private $glassTypeTable;
	
	private function getGlassTypeTable() {
		if (!$this->glassTypeTable) {
			$this->glassTypeTable = new GlassTypeTable($this->tuxDb->getInstance());
		}
		return $this->glassTypeTable;
		
	}
	
	public function getAllGlassTypes() {
		$glassTypeTable = $this->getGlassTypeTable();
		$select = $glassTypeTable->newSelect();
		$glassTypeTable->getSelect($select,array('glass_type_id','glass_name','glass_desc','global_image_id'));
		$resultSet = $glassTypeTable->selectWith($select);
		if ($resultSet->count() >0) {
			$arr = $resultSet->toArray();
			return $arr;
		}
		return null;		
	}
	
	public function getGlassTypeId($glassTypeName) {
		$select = $this->getGlassTypeTable()->newSelect();
		$this->getGlassTypeTable()->getSelect($select,array('glass_type_id'))->where(array('glass_name'=>$glassTypeName));
		$resultSet = $this->getGlassTypeTable()->selectWith($select);
		if ($resultSet->count() != 1) {
			return null;
		}
		$arr = $resultSet->toArray();
		return $arr[0]['glass_type_id'];
	}

	public function getGlassTypeName($glassTypeId) {
		$select = $this->getGlassTypeTable()->newSelect();
		$this->getGlassTypeTable()->getSelect($select,array('glass_name'))->where(array('glass_type_id'=>$glassTypeId));
		$resultSet = $this->getGlassTypeTable()->selectWith($select);
		if ($resultSet->count() != 1) {
			return null;
		}
		$arr = $resultSet->toArray();
		return $arr[0]['glass_name'];
	}
	
	public function updateGlassTypeName($rowId,$value) {
		$this->getGlassTypeTable()->update(array('glass_name'=>$value),array('glass_type_id'=>$rowId));
	}
	
	public function updateGlassTypeDesc($rowId,$value) {
		$this->getGlassTypeTable()->update(array('glass_desc'=>$value),array('glass_type_id'=>$rowId));
	}
	
	
}